clear

global b;
global I;
global Kd;
KArr = [1:0.01:2];
%K = KArr(1);
b = 0.02;
I = 0.004;

diez = 0;
cinco = 0;
uno = 0;
cero = 0;
for i=1:length(KArr)
    Kd=KArr(i);
    [T Z]=rk4sgral(0,1000,[0,0],100000,'thetapuntoe');
    error = ERP(Z(:,1),T);
%    if (min(error) < 0.1 && diez == 0)
%        display(Kd);
%        diez = 1
%    end
%    if (min(error) < 0.05 && cinco == 0)
%        display(Kd);
%        cinco = 1
%    end
    if (min(error) < 0.01 && uno == 0)
        display(Kd);
        uno = 1
    end
    if (min(error) < 0.001 && cero == 0)
        display(Kd);
        cero = 1
    end
    %K=KArr(i);
    %[T Z]=rk4sgral(0,1000,[0,0],10000,'theta');
    %erp=ERP(Z(:,1),T);
    %plot(T,erp, 'r-');
    %hold on;
end

%xlabel('Tiempo[s]');
%ylabel('ERP');

%hold off;

%res(:,1), thetaR(res(:,1)), 'b-');
